package cn.stylefeng.guns.modular.customer.wrapper;

import cn.stylefeng.guns.modular.course.entity.Course;
import cn.stylefeng.guns.modular.course.entity.CourseVideo;
import cn.stylefeng.guns.modular.course.service.CourseService;
import cn.stylefeng.guns.modular.course.service.CourseVideoService;
import cn.stylefeng.guns.modular.customer.entity.Customer;
import cn.stylefeng.guns.modular.customer.service.CustomerService;
import cn.stylefeng.roses.core.base.warpper.BaseControllerWrapper;
import cn.stylefeng.roses.core.util.SpringContextHolder;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

public class UserWarpper extends BaseControllerWrapper {

    public UserWarpper(Page<Map<String, Object>> page) {
        super(page);
    }

    private CustomerService customerService= SpringContextHolder.getBean(CustomerService.class);


    @Override
    protected void wrapTheMap(Map<String, Object> map) {
        Integer id=(Integer)map.get("id");
        Integer pid=(Integer)map.get("pid");
        Integer leader=(Integer)map.get("leader");
        String superiors="无";
        String supports="无";
        //查询上级领导昵称
        //父级
        Customer superior=customerService.getById(pid);
        //父级的父级
        Customer parent=new Customer();
        if(superior!=null&&superior.getPid()!=null) {
            parent = customerService.getById(superior.getPid());
        }
        //查询帮扶领导
        Customer support = customerService.getById(leader);
        //上级名称
        if(superior!=null&& StringUtils.isNotBlank(superior.getNickname())){
            superiors=superior.getNickname();
        }
        map.put("superior",superiors);
        //查询帮扶领导
        if(support!=null&& StringUtils.isNotBlank(support.getNickname())){
            supports=support.getNickname();
        }
        map.put("support",supports);
        Customer customer=new Customer();
        customer.setPid(id);
        List<Customer> customerList = customerService.customerList(customer);
        if(customerList!=null&&customerList.size()>0){
            map.put("type","1");
        }else{
            map.put("type","2");
        }
        //判断上级和上级的上级是否是社长
        if(superior!=null&&superior.getRole()!=null&&superior.getRole()==2){
            map.put("supports","1");
        }else if(parent!=null&&parent.getRole()!=null&&parent.getRole()==2){
            map.put("supports","1");
        }else{
            map.put("supports","2");
        }
    }
}
